﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Reflection;

namespace DMS.Business.Utility {
    public class WebFormUtils {
        public static T CreatePageEntry<T>(object page)
        {
            /*
            FieldInfo[] fields = page.GetType().GetFields();
            
            foreach (var fieldInfo in fields)
            {
                Console.WriteLine(string.Format("{0} = {1}",fieldInfo.FieldType,fieldInfo.GetValue(page)));

            }
             */
            T entry = BeanUtils.CreateObject<T>();
            // FillPageEntry(entry, page);
            return entry;
        }

        public static void FillPageEntry(object entry, object page) {
            if (entry == null || page == null) {
                return;
            }
            PropertyInfo[] props = entry.GetType().GetProperties();
            Type pageType = page.GetType();
            foreach (PropertyInfo prop in props)
            {
                FieldInfo field = pageType.GetField(prop.Name);
                if (field == null)
                {
                }
                else
                {
                    object propValue = field.GetValue(page);
                    propValue = TypeConvertHelper.Convert(propValue, prop.PropertyType);
                    prop.SetValue(entry, propValue, null);
                }
            }
        }

        public static void BindEntryToControls(object  entry,Control container)
        {
            
        }
    }
}
